home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / examples / tcl / x01.tcl < prev    next >
Text File  |  1994-08-09  |  3KB  |  164 lines

  1. # $Id: x01.tcl,v 1.3 1994/08/09 08:23:22 mjl Exp $
  2. # $Log: x01.tcl,v $
  3. # Revision 1.3  1994/08/09  08:23:22  mjl
  4. # Changed to new tclMatrix notation.
  5. #
  6. # Revision 1.2  1994/06/30  18:47:52  mjl
  7. # Minor label and commenting changes.
  8. #
  9. # Revision 1.1  1994/06/25  20:34:24  mjl
  10. # Demo program 1.  Now fully reproduces x01c plots.
  11. #
  12. #----------------------------------------------------------------------------
  13. # PLplot Tcl demo #1
  14. #
  15. # After sourcing, just type "1".
  16. #----------------------------------------------------------------------------
  17.  
  18. proc 1 {} {
  19.     global xscale yscale xoff yoff
  20.  
  21.     plssub 2 2
  22.  
  23. # First plot
  24.  
  25.     set xscale 6.0
  26.     set yscale 1.0
  27.     set xoff 0.0
  28.     set yoff 0.0
  29.  
  30.     plot1
  31.  
  32. # Second
  33.  
  34.     set xscale 1.0
  35.     set yscale 0.0014
  36.     set yoff   0.0185
  37.  
  38.     plsyax 5
  39.     plot1
  40.  
  41. # Third
  42.  
  43.     plot2
  44.  
  45. # Fourth
  46.  
  47.     plot3
  48.  
  49. # An eop is nice here.
  50.  
  51.     pleop
  52. }
  53.  
  54. # This is supposed to work just like the plot1() in x01c.c
  55.  
  56. proc plot1 {} {
  57.     global xscale yscale xoff yoff
  58.  
  59.     set npts 60
  60.     matrix x f $npts
  61.     matrix y f $npts
  62.  
  63.     for {set i 0} {$i < $npts} {incr i} {
  64.     x $i = [expr $xoff + $xscale * ($i + 1) / $npts]
  65.     y $i = [expr $yoff + $yscale * pow([x $i],2)]
  66.     }
  67.  
  68.     set xmax [x [expr $npts-1]]
  69.     set ymax [y [expr $npts-1]]
  70.  
  71.     matrix x1 f 6
  72.     matrix y1 f 6
  73.  
  74.     for {set i 0} {$i < 6} {incr i} {
  75.     set j [expr $i*10+3]
  76.     x1 $i = [x $j]
  77.     y1 $i = [y $j]
  78.     }
  79.  
  80.     plcol 1
  81.     plenv $xoff $xmax $yoff $ymax 0 0
  82.     plcol 6
  83.     pllab "(x)" "(y)" "#frPLplot Example 1 - y=x#u2"
  84.  
  85.     # plot the data points
  86.  
  87.     plcol 9
  88.     plpoin 6 x1 y1 9
  89.  
  90.     # draw the line through the data
  91.  
  92.     plcol 4
  93.     plline $npts x y
  94. }
  95.  
  96. # This is supposed to work just like the plot2() in x01c.c
  97.  
  98. proc plot2 {} {
  99.     plcol 1
  100.     plenv -2 10 -.4 1.2 0 1
  101.     plcol 2
  102.     pllab "(x)" "sin(x)/x" "#frPLplot Example 1 - Sinc Function"
  103.  
  104.     # Fill up the array
  105.  
  106.     matrix x1 f 101
  107.     matrix y1 f 101
  108.  
  109.     for {set i 0} {$i < 101} {incr i} {
  110.     set x [expr ($i - 19.)/6.]
  111.     x1 $i = $x
  112.     y1 $i = 1
  113.     if {$x != 0} { y1 $i = [expr sin($x)/$x] }
  114.     }
  115.  
  116.     plcol 3
  117.     plline 101 x1 y1
  118. }
  119.  
  120. # This is supposed to work just like the plot3() in x01c.c
  121.  
  122. proc plot3 {} {
  123.  
  124.     pladv
  125.     plvsta
  126.     plwind 0.0 360.0 -1.2 1.2
  127.  
  128. # Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y.
  129.  
  130.     plcol 1
  131.     plbox "bcnst" 60.0 2 "bcnstv" 0.2 2
  132.  
  133. # Superimpose a dashed line grid, with 1.5 mm marks and spaces. 
  134. # plstyl expects two integer matrices for mark and space!
  135.  
  136.     matrix mark i 1
  137.     matrix space i 1
  138.  
  139.     mark 0 = 1500
  140.     space 0 = 1500
  141.     plstyl 1 mark space
  142.  
  143.     plcol 2
  144.     plbox "g" 30.0 0 "g" 0.2 0
  145.  
  146.     mark 0 = 0
  147.     space 0 = 0
  148.     plstyl 0 mark space
  149.  
  150.     plcol 3
  151.     pllab "Angle (degrees)" "sine" "#frPLplot Example 1 - Sine function"
  152.  
  153.     matrix x f 101
  154.     matrix y f 101
  155.  
  156.     for {set i 0} {$i < 101} {incr i} {
  157.     x $i = [expr 3.6 * $i]
  158.     y $i = [expr sin([x $i] * 3.141592654 / 180.0)]
  159.     }
  160.  
  161.     plcol 4
  162.     plline 101 x y
  163. }
  164.